package org.bit.lesson04;

public class Demo403 {
    public static void main(String[] args) throws InterruptedException {
        Counter403 counter = new Counter403();
        Counter403 counter1 = new Counter403();

        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                counter.increase();
            }
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                counter1.increase();
            }
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println("count = " + Counter403.count);
    }
}

class Counter403 {

    public static int count = 0;

    public synchronized void increase() {
        count++;
    }

}
